package top.lyc829.zzl_android.ui.profile;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import okhttp3.Response;
import top.lyc829.zzl_android.MyApp;
import top.lyc829.zzl_android.logic.bean.ConcernedInfoBean;
import top.lyc829.zzl_android.logic.bean.ResultBean;
import top.lyc829.zzl_android.logic.bean.UserInfoBean;
import top.lyc829.zzl_android.logic.network.Network;
import top.lyc829.zzl_android.logic.util.HttpUtil;
import top.lyc829.zzl_android.logic.util.Url;
import top.lyc829.zzl_android.logic.util.Utils;
import top.lyc829.zzl_android.logic.util.gson.JsonUtilNew;

public class ConcernedViewModel extends ViewModel {
    private MutableLiveData<ConcernedInfoBean> ConcernedInfoBeanMutableLiveData;

    public ConcernedViewModel(){
        this.ConcernedInfoBeanMutableLiveData=new MutableLiveData<>();
    }

    public MutableLiveData<ConcernedInfoBean> getConcernedBeanMutableLiveData(){
        if(ConcernedInfoBeanMutableLiveData==null)
        {
            ConcernedInfoBeanMutableLiveData=new MutableLiveData<>();
        }
        return ConcernedInfoBeanMutableLiveData;
    }
    public void getConcernedInfo(int user_id)
    {

        Network.getConcernedInfo(user_id, new HttpUtil.MyCallback() {
            @Override
            public void success(Response res) throws IOException {
                String resultStr = res.body().string();
                Utils.Sout(resultStr);
                ResultBean<ConcernedInfoBean> resultBean = JsonUtilNew.fromJsonObject(resultStr, ConcernedInfoBean.class);
                if(resultBean.getCode().equals(200))
                {
                    getConcernedBeanMutableLiveData().postValue(resultBean.getData());
                }
                else
                {
                    failed(new IOException(resultBean.getMsg()));
                }
            }

            @Override
            public void failed(IOException e) {
                Utils.Sout(e.getMessage());
            }
        });

    }

}
